import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)


//公用的store
import getters from './getters'
import actions from './actions'
import mutations from './mutations'

import createLogger from 'vuex/dist/logger'
//判断环境变量
const debug = process.env.NODE_ENV !== 'production'

console.log(process.env)

//引入模块化的store
import prpmCheck from './modules/prpmcheck/index.js'
import counter from './modules/counter/index.js'

const state = {
  userInfo: {
    name: 'jkj',
  },
  test:0,
}

export default new Vuex.Store({
  modules: {
    prpmCheck,
    counter
  },
  state,
  getters,
  actions,
  mutations,
  strict: false,   // 不采用严格模式
  plugins: debug ? [
    //createLogger(),   //会一直打印state的状态 ,有点烦
    createPersistedState({
      storage: {
        getItem: key => wx.getStorageSync(key),
        setItem: (key, value) => wx.setStorageSync(key, value),
        removeItem: key => {}
        // removeItem: key => wx.clearStorageSync(key)
      }
    })
  ] : [
    createPersistedState({
      storage: {
        getItem: key => wx.getStorageSync(key),
        setItem: (key, value) => wx.setStorageSync(key, value),
        removeItem: key => {}
      }
    })
  ]
})
